package com.designpattern.templatemethod;

/**
 * 项目名称: java_algorithm
 * @ClassName TemplateMethodTest
 * @Description
 * @Author huipanxing huipanxing@chinasofti.com   @Date 2021/9/10 15:29
 */
public class TemplateMethodTest {

    public static void main(String[] args) {
        AbstractClass abstractClass=new SubClass();
        abstractClass.operation();
        System.out.println("---------------------------");
        AbstractClass abstractClass1=new SubClass1();
        abstractClass1.operation();
    }
}

abstract class AbstractClass{
    public void operation(){
        System.out.println("pre...");
        System.out.println("step1...");
        System.out.println("step2...");
        templateMethod();
    }
    abstract protected void templateMethod();
}

class SubClass extends AbstractClass{

    @Override
    protected void templateMethod() {
        System.out.println("SubClass executed...");
    }
}

class SubClass1 extends AbstractClass{

    @Override
    protected void templateMethod() {
        System.out.println("SubClass1 executed...");
    }
}